package com.sl.mes.db.service;

import java.time.LocalDateTime;

import javax.annotation.Resource;

import com.sl.mes.db.dao.MesAgencyShareMapper;
import com.sl.mes.db.vo.MesAgencyShare;
import com.sl.mes.db.vo.MesAgencyShareExample;
import org.springframework.stereotype.Service;

@Service
public class MesAgencyService {

	@Resource
	private MesAgencyShareMapper agencyShareMapper;

	/**
	 * 获取代理用户的分享对象海报图
	 * @param userId
	 * @param type
	 * @param shareObjId
	 * @return
	 */
	public String getMesAgencyShare(Integer userId, Integer type, Integer shareObjId) {
		String shareUrl = null;
		MesAgencyShareExample example = new MesAgencyShareExample();
		example.or().andUserIdEqualTo(userId).andTypeEqualTo(type).andShareObjIdEqualTo(shareObjId);
		MesAgencyShare das = agencyShareMapper.selectOneByExample(example);
		if (das != null) {
			shareUrl = das.getShareUrl();
		}
		return shareUrl;
	}

	/**
	 * 存储代理用户的分享对象海报图
	 * @param userId
	 * @param type
	 * @param shareObjId
	 * @param shareUrl
	 */
	public void saveMesAgencyShare(Integer userId, Integer type, Integer shareObjId, String shareUrl) {
		MesAgencyShare record = new MesAgencyShare();
		record.setUserId(userId);
		record.setType(type);
		record.setShareObjId(shareObjId);
		record.setShareUrl(shareUrl);
		record.setAddTime(LocalDateTime.now());
		record.setUpdateTime(LocalDateTime.now());
		agencyShareMapper.insert(record );
	}
}
